package edu.thu.studio.ormdesigner.model;

import java.text.Collator;
import java.util.Comparator;

import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

/**
 * 抽象的设计模型，用于数据模型，包含基本的ID、名称和描述信息
 *
 */
public abstract class AbstractObjectModel extends AbstractModel implements Comparable<AbstractObjectModel>, ObjectModel {
    
    private static final long serialVersionUID = -7450893485538582071L;
    
    @XStreamAsAttribute()
    protected String name;
    
    @XStreamAsAttribute()
    protected String code;
    
    @XStreamAsAttribute()
    private String stereotype;
    
    protected String comment;
    
    public String getCode() {
        return code;
    }
    
    public void setCode(String code) {
        this.code = code;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getComment() {
        if (null != comment)
            return comment;
        return "";
    }
    
    public void setComment(String comment) {
        this.comment = comment;
    }
    
    public int compareTo(AbstractObjectModel other) {
        int compareTo = 0;
        Comparator<Object> comparator = Collator.getInstance(java.util.Locale.CHINA);
        if (null != this.getName() && null != other.getName()) {
            compareTo = comparator.compare(this.getName().toUpperCase(), other.getName().toUpperCase());
        }
        
        if (compareTo == 0) {
            if (null != this.getCode() && null != other.getCode()) {
                compareTo = comparator.compare(this.getCode().toUpperCase(), other.getCode().toUpperCase());
            }
        }
        
        return compareTo;
    }
    
    public String getStereotype() {
        if (null != stereotype)
            return stereotype;
        return "";
    }
    
    public void setStereotype(String stereotype) {
        this.stereotype = stereotype;
    }
    
}
